﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script src="~/Content/scripts/plugins/layout/jquery.layout.js"></script>
<script>
    var organizeId = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    var keyValue = request('keyValue');
    var FeeItem = "", OperateMemo;
    var CalculateType;
    $(function () {
        InitialPage();
        GetTree();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        $(".ui-layout-center").css("background", "#ffffff");
        $(".center-Panel").css("border", "0");
        $(".ui-layout-west").css("background", "#ffffff");
        $(".ui-layout-resizer").css("background", "#ffffff");
        $(".gridPanel table").css("border", "1px solid #ccc");
        $(".titlePanel").css("height", "40px").css("line-height", "40px");
        //所属机构
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJson",
            description: "==请选择==",
            height: "250px",
            click: function (item) {
                organizeId = item.id;
            }
        });
        $("#OrganizeId").ComboBoxTreeSetValue(organizeId);
        $("input[type=radio]").change(function () {
            $("#CustomerId").val("").attr("title", "");
            $("#PStructId").val("").attr("title", " ");
        });
        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "../../FinancialManage/ReceivableFeeItems/GetFormJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data.entity);
                    OperateMemo = data.entity.OperateMemo;
                    $('#Basic input[name="CustomerType"][value=' + data.entity.CustomerType + ']').attr("checked", true);
                    $("#CustomerId").val(data.CustomerName).attr("title", data.entity.CustomerId);
                    $("#PStructId").val(data.PStructName).attr("title", data.entity.PStructId);
                    $("#ItemName").text(data.ItemName);
                    FeeItem = data.entity.ItemId;
                    $("#ReceiveYear").val(data.entity.ReceiveMonth.substring(0, 4));
                    $("#ReceiveMonth").val(data.entity.ReceiveMonth.substring(4, 6));
                    $("#AccMonthYear").val(data.entity.AccMonth.substring(0, 4));
                    $("#AccMonthMonth").val(data.entity.AccMonth.substring(4, 6));
                    organizeId = data.entity.OrganizeId;
                }
            });
        }
    }
    //加载树
    function GetTree() {
        var item = {
            height: $(window).height() - 41.5,
            url: "../../FinancialManage/FeeItems/GetTreeFeeItemsList",
            onnodeclick: function (item) {
                if (FeeItem != item.id && item.id != "2") {
                    FeeItem = item.id;
                    $("#ItemName").text(item.text);
                    GetFeeItem();
                }
            }
        };
        $("#itemTree").treeview(item);
    }


    function GetFeeItem() {
        //获取表单
        if (!!FeeItem) {
            $.SetForm({
                url: "../../FinancialManage/FeeItems/GetFormJson",
                param: { keyValue: FeeItem },
                success: function (data) {
                    CalculateType = data.CalculateType;
                    $("#UnitPrice").val(data.UnitPrice);
                }
            });
        }
    }

    function DataItemSelect() {
        if (organizeId == "") {
            dialogMsg("请先选择机构", 0);
            return;
        }
        var Type = $('#Basic input[name="CustomerType"]:checked ').val();
        if (!Type) {
            dialogMsg("请先选择客户类型", 0);
            return;
        }
        else {
            var options = {};
            switch (Type) {
                case "1":
                    options["type"] = 1;
                    options["data"] = [{ "id": "CustomerId" }, { "id": "PStructId" }];
                    options["organizeid"] =organizeId;
                    break;
                case "2":
                    options["type"] = 6;
                    options["data"] = [{ "id": "CustomerId" }];
                    options["organizeid"] = organizeId;
                    break;
                case "3":
                    options["type"] =1;
                    options["data"] = [{ "id": "CustomerId" }];
                    options["organizeid"] = organizeId;
                    break;
                default:

            }
            //switch (Type) {
            //    case "1": options = "?keyValue=PStructId&objectA=CustomerId&objectD=PStructId&type=1&organizeid=" + organizeId; break;
            //    case "2": options = "?keyValue=CustomerId&type=13&organizeid=" + organizeId; break;
            //    case "3": options = "?keyValue=PStructId&objectA=CustomerId&objectD=PStructId&type=1&organizeid=" + organizeId; break;
            //    default:
            //        break;
            //}
            DataItemClick(JSON.stringify(options));
        }
    }

    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        if (!FeeItem) {
            dialogMsg('请选择费项！', 0); return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        postData["ReceiveMonth"] = $("#ReceiveYear").val() + $("#ReceiveMonth").val();
        postData["AccMonth"] = $("#AccMonthYear").val() + $("#AccMonthMonth").val();
        if (!keyValue)
            postData["State"] = 0;
        postData["CustomerType"] = $('#Basic input[name="CustomerType"]:checked ').val()
        postData["OperateMemo"] = OperateMemo;
        postData["CustomerId"] = $("#CustomerId").attr("title");
        postData["PStructId"] = $("#PStructId").attr("title");
        postData["ItemId"] = FeeItem;
        postData["IsAudit"] = 0;
        $.SaveForm({
            url: "../../FinancialManage/ReceivableFeeItems/SaveForm?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
    }
</script>
<style>
    html, body {
        height: 100%;
        width: 100%;
    }
</style>

<div class="ui-layout" id="layout" style="height: 695px; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="gridPanel">
                <table id="Basic" class="form">
                    <tr>
                        <th class="formTitle">所属机构<font face="宋体">*</font></th>
                        <td class="formValue">
                            <div id="OrganizeId" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">客户类型</th>
                        <td class="formValue">
                            <input type="radio" name="CustomerType" value="1" />房屋业户
                            <input type="radio" name="CustomerType" value="2" />供应商
                            <input type="radio" name="CustomerType" value="3" />其他
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">客户名称</th>
                        <td class="formValue">
                            <div class="input-group" style="width: 100%;">
                                <input id="CustomerId" type="text" class="form-control BaseClass" isvalid="yes" checkexpession="NotNull">
                                <span class="input-group-btn BaseClass">
                                    <a onclick="DataItemSelect()" class="form-control BaseClass" style="cursor: pointer"><i class="fa fa fa-book " style=" font-size: 20px; padding-right: 5px; padding-top: 3px; color: gray"></i></a>
                                </span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">相关房屋</th>
                        <td class="formValue">
                            <input id="PStructId" type="text" class="form-control" readonly>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="titlePanel">
                <label>收费项目&nbsp;&nbsp;&nbsp;</label><h4 style="display: inline;color:red;" id="ItemName">暂无</h4>
            </div>
            <div class="gridPanel">
                <table id="FeeItems" class="form">
                    <tr>
                        <td class="formTitle">单价</td>
                        <td class="formValue">
                            <input id="UnitPrice" type="number" isvalid="yes" checkexpession="NotNull" class="form-control" />
                        </td>
                        <td class="formTitle">用量</td>
                        <td class="formValue">
                            <input id="Quantity" type="number" isvalid="yes" checkexpession="NotNull" value="1" class="form-control" />
                        </td>
                        <td class="formTitle">系数</td>
                        <td class="formValue">
                            <input id="Coefficient" type="number" isvalid="yes" checkexpession="NotNull" value="1" class="form-control" />
                        </td>
                    </tr>
                    <tr>
                        <td class="formTitle">应收金额</td>
                        <td class="formValue">
                            <input id="ReceiveAmount" type="number" isvalid="yes" checkexpession="NotNull" class="form-control" />
                        </td>
                        <td class="formTitle">优惠前金额</td>
                        <td class="formValue">
                            <input id="Cost" type="number" isvalid="yes" checkexpession="NotNull" class="form-control" />
                        </td>
                        <td class="formTitle">应收年月</td>
                        <td class="formValue">
                            <input id="ReceiveYear" type="text" class="form-control input-wdatepicker" style="width:42%;display:inherit;" onfocus="WdatePicker({ dateFmt: 'yyyy' })" value="@DateTime.Now.ToString("yyyy")" />年
                            <input id="ReceiveMonth" type="text" class="form-control input-wdatepicker" style="width: 42%; display: inherit;" onfocus="WdatePicker({ dateFmt: 'MM' })" value="@DateTime.Now.ToString("MM")" />月
                        </td>
                    </tr>
                    <tr>
                        <td class="formTitle">账单日</td>
                        <td class="formValue">
                            <input id="BillDay" type="text" isvalid="yes" checkexpession="NotNull" class="form-control input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
                        </td>
                        <td class="formTitle">付款期限</td>
                        <td class="formValue">
                            <input id="LimitDate" type="text" isvalid="yes" checkexpession="NotNull" class="form-control input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
                        </td>
                        <td class="formTitle">滞纳金起算日</td>
                        <td class="formValue">
                            <input id="DelayBeginDate" type="text" isvalid="yes" checkexpession="NotNull" class="form-control input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
                        </td>
                    </tr>
                    <tr>
                        <td class="formTitle">权责年月</td>
                        <td class="formValue">
                            <input id="AccMonthYear" type="text" class="form-control input-wdatepicker" style="width:42%;display:inherit;" onfocus="WdatePicker({ dateFmt: 'yyyy' })" value="@DateTime.Now.ToString("yyyy")" />年
                            <input id="AccMonthMonth" type="text" class="form-control input-wdatepicker" style="width: 42%; display: inherit;" onfocus="WdatePicker({ dateFmt: 'MM' })" value="@DateTime.Now.ToString("MM")" />月
                        </td>
                        <td class="formTitle">计费起始日</td>
                        <td class="formValue">
                            <input id="BeginDate" type="text" isvalid="yes" checkexpession="NotNull" class="form-control input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', maxDate: '#F{$dp.$D(EndDate)}' })" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
                        </td>
                        <td class="formTitle">计费终止日</td>
                        <td class="formValue">
                            <input id="EndDate" type="text" isvalid="yes" checkexpession="NotNull" class="form-control input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', minDate: '#F{$dp.$D(BeginDate)}' })" value="@DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd")" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">
                            说明
                        </th>
                        <td class="formValue" colspan="5">
                            <textarea id="Description" class="form-control" style="height: 70px;"></textarea>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>
